/**
 * SysController.java 
 * Copyright © 2015-3015, 杭州泊享网络科技有限公司
 * 
 * @author wenlong Hua
 * @create 2015年11月9日
 */
package com.pshare.artemis.config;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.pshare.artemis.config.service.ConfigService;
import com.pshare.framework.controller.BaseController;
import com.pshare.util.WXSignUtils;

/**
 * wx配置Contrller
 */
@Controller
public class ConfigController extends BaseController{

	private static final Logger logger = Logger.getLogger(ConfigController.class);
	
	@Autowired
	private ConfigService configService;
	
	/**
	 * wx验签
	 * @return String
	 */
	@RequestMapping(value = "/checktoken", method = RequestMethod.GET)
	public String  checkToken(HttpServletRequest request,HttpServletResponse response)throws ServletException, IOException {
		String signature = request.getParameter("signature");  
        String timestamp = request.getParameter("timestamp");  
        String nonce = request.getParameter("nonce");  
        String echostr = request.getParameter("echostr");
        logger.info("signature:"+signature+"++++echostr:"+echostr);
		if(WXSignUtils.checkSignature(signature, timestamp, nonce,echostr)){
			response.getWriter().print(echostr);
			logger.info("验签成功");
			//验签通过后获取一次 accesstoken
			configService.getWXAccessToken();
		}else{
			logger.info("验签失败");	
		}
			
		return null ;
	}
	
}
